package animator.phantom.paramedit;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.renderer.*;
import animator.phantom.renderer.param.*;
import animator.phantom.gui.GUIResources;
import animator.phantom.controller.GUIComponents;
import animator.phantom.controller.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import animator.phantom.gui.modals.DialogUtils;
import animator.phantom.renderer.threedee.Phantom3DCamera;

/**
* A GUI editor component for setting the value of a <code>ColoParam</code> parameter. Pressing button opens a color chooser dialog.
*/
public class Camera3DSelect extends JPanel implements ActionListener, UndoListener
{
	private IntegerParam cameraID;
	private JButton changeButton;
	private JLabel cameraLabel;

	/**
	* Constructor with parameter to be edited and label text.
	* @param editColor <code>ColoParam</code> that is edited with this editor.
	* @param info Displayed name for editor and parameter.
	*/
	public Camera3DSelect( IntegerParam cameraID )
	{

		this.cameraID = cameraID;

		JLabel textLabel = new JLabel("Camera:");
		textLabel.setFont( GUIResources.PARAM_EDIT_LABEL_FONT );

		String cameraName = ThreeDeeController.getCameraName( cameraID.get() );
		cameraLabel = new JLabel( cameraName );
		cameraLabel.setFont( GUIResources.PARAM_EDIT_LABEL_FONT );

		changeButton = new JButton( "Select Camera" );
		changeButton.addActionListener(this);

		JPanel leftPanel = new JPanel();
		leftPanel.setLayout( new BoxLayout( leftPanel, BoxLayout.X_AXIS) );
		leftPanel.setPreferredSize( ParamEditResources.EDIT_ROW_HALF_SIZE );
		//leftPanel.add( textLabel );
		leftPanel.add( cameraLabel );
		leftPanel.add( Box.createHorizontalGlue() );

		JPanel rightPanel = new JPanel();		
		rightPanel.setLayout( new BoxLayout( rightPanel, BoxLayout.X_AXIS) );
		rightPanel.setPreferredSize( ParamEditResources.EDIT_ROW_HALF_SIZE );
		rightPanel.add( changeButton );
		rightPanel.add( Box.createHorizontalGlue() );

		setLayout( new BoxLayout( this, BoxLayout.X_AXIS) );
		add( rightPanel );
		add( leftPanel );

		setPreferredSize( ParamEditResources.EDIT_ROW_SIZE );
		setMaximumSize( ParamEditResources.EDIT_ROW_SIZE );
	}

	/**
	* Called after undo has been done to set displayed color to current state.
	*/
	public void undoDone()
	{
		String cameraName = ThreeDeeController.getCameraName( cameraID.get() );
		cameraLabel.setText( cameraName );
	}

	/**
	* Handles button presses.
	*/
	public void actionPerformed( ActionEvent e )
	{
		//DialogUtils.displayColorSelect( this, editColor.get() );
		int newCameraID  = ThreeDeeController.getNewCameraID( cameraID.get() );
		if( newCameraID == cameraID.get() )
			return;
		UpdateController.valueChangeUpdate( UpdateController.PARAM_EDIT );
		cameraID.set( newCameraID );
		String cameraName = ThreeDeeController.getCameraName( cameraID.get() );
		cameraLabel.setText( cameraName );
	}

}//end class
